<template>
  <div class="news-detail">
    <van-nav-bar title="新闻详情" left-text="返回" left-arrow @click-left="$router.go(-1)" class="fixed-top"/>
    <div class="news-box">
      <div>
        <h1 class="news-title">{{newsDetailData.title}}</h1>
        <p class="news-info">
          <span>{{newsDetailData.add_time | dateFormat}}</span>
          <span>{{newsDetailData.click}}次浏览</span>
          <span>分类：经济民生</span>
        </p>
      </div>
      <div class="news-content" v-html="newsDetailData.content"></div>
      <comment :id="newsid"></comment>
    </div>
  </div>
</template>
<script>
import { getNewsDetail } from '@/api'
import Comment from '@/components/comment'
export default {
  components: {
    Comment
  },
  data () {
    return {
      newsid: +this.$route.params.id,
      newsDetailData: {}
    }
  },
  created () {
    this.initList()
  },
  methods: {
    initList () {
      getNewsDetail(this.newsid)
        .then(res => {
          // console.log(res)
          this.newsDetailData = res.data.message[0]
          // console.log(this.newsDetailData)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.news-detail {
  .fixed-top {
    background-color: green;
      width: 100%;
      position: fixed;
      top: 0;
      color: white;
  }
  .news-box {
    padding: 0 8px;
    margin-top: 46px;
  }
  .news-title {
    font-size: 14px;
    font-weight: bold;
  }
  .news-info {
    font-size: 12px;
    color: #26a2ff;
    display: flex;
    justify-content: space-between;
  }
  .news-content {
    font-size: 12px;
  }
}
</style>
